package com.hxzy.action;

import java.io.FileNotFoundException;
import java.io.InputStream;

import com.hxzy.service.AttachmentService;
import com.hxzy.service.AttachmentServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

public class DownloadAction extends ActionSupport {

	private static final long serialVersionUID = -5977888195768286168L;
	private InputStream inputStream;
	private String filename;
	private String savePath;
	private String id;
	private String contentType;
	private long contentLength;
	private AttachmentService attachmentSevice=new AttachmentServiceImpl();
	
	@Override
	public String execute() throws Exception {
		//Attachment attachment=this.attachmentSevice.get(Long.parseLong(id));
	/*	if(attachment==null){
			addActionError("下载文件不存在");
			return INPUT;
		}*/
		return SUCCESS;
	}
	
	public InputStream getInputStream() throws FileNotFoundException {
		return this.attachmentSevice.download(Long.parseLong(id));
	}
	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	//public String getFilename() {
		//Attachment attachment=this.attachmentSevice.get(Long.parseLong(id));
		//return new URLEncoder().encode(attachment.getFilename(), "utf-8");
	//}
	public void setFilename(String filename) {
		this.filename = filename;
	}
	public String getSavePath() {
		return savePath;
	}
	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public long getContentLength() {
		return contentLength;
	}

	public void setContentLength(long contentLength) {
		this.contentLength = contentLength;
	}

	public AttachmentService getAttachmentSevice() {
		return attachmentSevice;
	}

	public void setAttachmentSevice(AttachmentService attachmentSevice) {
		this.attachmentSevice = attachmentSevice;
	}
	
	
}
